package com.sqsf.service.impl;

import com.sqsf.javabean.Users;
import com.sqsf.mapper.UserMapper;
import com.sqsf.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;
    @Override
    public Users login(String username, String password) {
        return userMapper.selectByUsernameAndPassword(username,password);
    }

    @Override
    public List<Users> findAll() {
        return userMapper.selectU_R();
    }

    @Override
    @Transactional
    public void add(Users users, int roleId) {
        userMapper.insert(users);
        userMapper.insertU_R(users.getId(),roleId);
    }

    @Override
    @Transactional
    public void delete(int id) {
        userMapper.deleteU_R(id);
        userMapper.deleteById(id);
    }

    @Override
    public Users FindById(int id) {
        return userMapper.selectById(id);
    }

    @Override
    @Transactional
    public void edit(Users users, int roleId) {
        userMapper.update(users);
        userMapper.updateU_R(users.getId(),roleId);
    }
}
